<%--
    Document   : home
    Created on : Oct 23, 2011, 5:06:42 PM
    Author     : Group 106
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="error.jsp"%>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List" %>
<%@page import="com.aptech.model.RealEstateType" %>
<%@page import="com.aptech.model.RealEstateStyle" %>
<%@page import="com.aptech.model.User" %>
<%@page import="com.aptech.model.realEstateInfo" %>
<%@page import="com.aptech.DAO.realEstateTypeDAO" %>
<%@page import="com.aptech.DAO.realEstateStyleDAO" %>
<%@page import="com.aptech.DAO.realEstateDAO" %>

<%@ taglib prefix="page" uri="/WEB-INF/tlds/phantrang.tld" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <link rel="stylesheet" href="CSS/css.css" />
        <link rel="stylesheet" href="CSS/msh_style.css"/>
        <link rel="stylesheet" href="CSS/gallery_style.css"/>
        <link rel="stylesheet" href="CSS/mn_left.css" />
        <link rel="stylesheet" href="CSS/mn_search.css" />
        <link rel="stylesheet" href="CSS/css_realEstateInfor.css" />
        <!-- <link rel="stylesheet" href="CSS/css_header.css" />
             <link rel="stylesheet" href="CSS/css_footer.css" /> -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <%
                User objUser = null;
                String userID = "";
                ArrayList<RealEstateType> listRealStateType = null;
                int realEstateTypeID = 0;
                if (request.getSession().getAttribute("user") != null) {
                    realEstateTypeDAO objRealEstateTypeDAO = new realEstateTypeDAO();
                    realEstateDAO objRealEstateDAO = new realEstateDAO();
                    objUser = (User) request.getSession().getAttribute("user");
                    userID = objUser.getUserID() + "";
                    listRealStateType = new ArrayList<RealEstateType>();
                    listRealStateType = objRealEstateTypeDAO.getAllRealEstateType();


    %>
    <body>

        <div id="wrap">
            <%@include file="header.jsp" %>
            <div class="clear_with_heght"></div><!--End .clear-->
            <div id="main">
                <div id="left_sidebar">
                    <%@include file="leftSidebar.jsp" %>
                </div><!--End #left_sidebar-->
                <div id="content">
                    <%@include file="search.jsp" %>
                    <div class="clear"></div><!--End .clear-->
                    <%
                                        try {
                                            realEstateTypeID = Integer.parseInt(request.getParameter("realEstateTypeID"));
                                        } catch (NumberFormatException e) {
                                            e.printStackTrace();
                                        }
                                        ArrayList<realEstateInfo> listrealEstateInfo;
                                        listrealEstateInfo = objRealEstateDAO.getRealEstateByType(realEstateTypeID);
                                        int pageno = 0;

                    %>
                    <div id="realEstateInfor">
                        <div id="mn_realEstateInfor_header_left"></div>
                        <div id="mn_realEstateInfor_header_center">House</div>
                        <div id="mn_realEstateInfor_header_right"></div>

                        <!--				<div id="mn_houseInfo_content_left"></div> -->
                        <div class="clear"></div><!--End .clear-->
                        <div class="mn_realEstateInfor_content_center">

                            <%
                                                if (!listrealEstateInfo.isEmpty()) {
                                                    int intPage = 1;
                                                    List<realEstateInfo> subListRealEstateInfo;
                                                    int totalPage = 0;
                                                    if (listrealEstateInfo.size() % 10 != 0) {
                                                        if (listrealEstateInfo.size() > 10) {
                                                            totalPage = (listrealEstateInfo.size() / 10) + 1;
                                                        } else {
                                                            totalPage = listrealEstateInfo.size() / 10;
                                                        }
                                                    }
                                                    try {
                                                        intPage = Integer.parseInt(request.getParameter("pageno"));
                                                    } catch (NumberFormatException ex) {
                                                        intPage = 1;
                                                    }
                                                    if (intPage == 1 && totalPage > 1) {
                                                        subListRealEstateInfo = listrealEstateInfo.subList((intPage - 1) * 10, (intPage * 10));
                                                    } else if (intPage == 1 && totalPage == 1) {
                                                        subListRealEstateInfo = listrealEstateInfo.subList(((intPage - 1) * 10), listrealEstateInfo.size());
                                                    } else if (intPage < totalPage) {
                                                        subListRealEstateInfo = listrealEstateInfo.subList(((intPage - 1) * 10), (intPage * 10));
                                                    } else {
                                                        subListRealEstateInfo = listrealEstateInfo.subList(((intPage - 1) * 10), listrealEstateInfo.size());
                                                    }
                                                    for (realEstateInfo realEstate : subListRealEstateInfo) {

                                                        if (intPage <= 1) {
                                                            pageno = subListRealEstateInfo.indexOf(realEstate);
                                                        } else {
                                                            pageno = ((intPage - 1) * 10) + subListRealEstateInfo.indexOf(realEstate);
                                                        }
                                                        //body cho vao day


                            %>
                            <div class="realEstateTitle"><img src="Img/icon_nha.gif" /> <a href="realEstateDetail.jsp?realEstateID=<%=realEstate.getRealEstateID()%>"><%=realEstate.getRealEstateTitle()%> </a></div>
                            <div class="startDate">Post Date : <%=realEstate.getStartDate()%></div>
                            <div class="realEstateImage"><img src="Imgs/realEstate_Imgs/<%= realEstate.getRealEstateImage()%>" width="100" height="100" /></div>
                            <div class="realEstateDescription"><%=realEstate.getDescription()%>...<a href="realEstateDetail.jsp?realEstateID=<%=realEstate.getRealEstateID()%>"> view detail</a></div>
                            <div class="footerInfo"></div>
                            <% }%>
                            <div class="PhanTrang">
                                <page:phantrang total="<%=listrealEstateInfo.size()%>" cursor=" ${param.pageno}" />
                            </div>
                        </div>
                        <%
                                            }
                        %>
                        <!--				<div id="mn_houseInfo_content_right"></div> -->
                        <div class="clear"></div><!--End .clear-->
                        <div id="mn_realEstateInfor_footer_left"></div>
                        <div id="mn_realEstateInfor_footer_center"></div>
                        <div id="mn_realEstateInfor_footer_right"></div>
                    </div><!--End #realEstateInfor-->
                </div><!--End #content-->
            </div><!--End #main-->
            <div class="cleaner_with_height">&nbsp;</div><!--End .clear-->
            <div id="msh_footer_panel" style="width: 942px">
                Copyright © 2011 <a href="aptech.vn">Ha Noi - Aptech</a> | <a href="home.jsp" target="_parent">Website My Sweet Home</a> by <a href="home.jsp" target="_blank">Group 106</a>
            </div><!--End #footer-->
            <div class="clear"></div><!--End .clear-->
        </div><!--End #wrap-->
        <div class="clear"></div><!--End .clear-->
    </body>
    <%
                } else {
                    response.sendRedirect("login.jsp");
                }
    %>
</html>